package com.zsix.system.strategy.copyFor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 抄送
 */
@Component
public class CCContext {
    /**
     * 抄送策略对象
     */
    private final List<CCStrategy> ccStrategyList;
    /**
     * 构造函数
     * @param ccStrategyList
     */
    public CCContext(List<CCStrategy> ccStrategyList){
        this.ccStrategyList=ccStrategyList;
    }
    /**
     * server容器
     */
    private Map<String, CCStrategy> ccStrategyMap = new HashMap<>();

    /**
     * 初始化
     */
    @PostConstruct
    public void init(){
        ccStrategyMap=ccStrategyList.stream()
                .collect(Collectors.toMap(CCStrategy::getType, o -> o));
    }
    /**
     * 获取方法
     * @param serviceType
     * @return
     */
    public CCStrategy getService(String serviceType){
        return ccStrategyMap.get(serviceType);
    }
}
